import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2022-08-19
 * Time: 15:51
 */

/*class Student {
    private String name;
    private int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}*/

public class Test1_0819 {

    //实现 Comparable 接口 并实现其中得comparableTo方法
/*    public static void main(String[] args) {

        Student[] students = new Student[]{
                new Student("张三", 97),
                new Student(";李四", 98),
                new Student("王五", 95),
                new Student("赵六", 93)};

        Arrays.sort(students);*/
        //抛出异常 Student 不能直接转为Comparable使用
        //System.out.println(Arrays.toString(students));

    public static void main1(String[] args) {
        Student student1 = new Student("张三",97);
        Student student2 = new Student("张三",99);
        if(student1.compareTo(student2)>0){
            System.out.println("student1>student2");
        }else
        {
            System.out.println("student1<student2");
        }
    }

    //public static void sort()

    public static void main(String[] args) {
        Student[] students1 = new Student[]{
                new Student("zhangsan", 97),
                new Student(";lisi", 98),
                new Student("wangwu", 95),
                new Student("zhaoliu", 93)};

        Arrays.sort(students1);
        System.out.println(Arrays.toString(students1));

        System.out.println("===========================");
        Student[] students2 = new Student[]{
                new Student("张三", 97),
                new Student(";李四", 98),
                new Student("王五", 95),
                new Student("赵六", 93)};

        Arrays.sort(students2);
        System.out.println(Arrays.toString(students2));

    }

}
class Student implements Comparable <Student>{

    public String name;
    public int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.name.compareTo(o.name);
    }
}